import pytest


@pytest.fixture(autouse=True)
def test_fixture_autouse():
    print('autouse_fixture_start')
    yield  # 自动执行的 fixture , 返回值没用 .
    print('autouse_fixture_end')


@pytest.fixture(scope='function')
def fixture_function_common_oo1():
    print()
    print('fixture_function_common_oo1_start')
    yield
    print('fixture_function_common_oo1_end')
    print()


@pytest.fixture(scope='function')
def fixture_function_common_oo2():
    print()
    print('fixture_function_common_oo2_start')
    yield
    print('fixture_function_common_oo2_end')
    print()


@pytest.fixture()
def fixture_function_oo1():
    """
    未指定 scope
    scope 默认 function
    """
    print('fixture_function_oo1_stard')
    yield 'fixture_function_oo1`s return'
    print('fixture_function_oo1_end')


@pytest.fixture(scope='function')
def fixture_function_oo2():
    print('fixture_function_oo2_start')
    yield 'fixture_function_oo2`s return'
    print('fixture_function_oo2_end')


@pytest.fixture(scope='function')
def fixture_function_oo3():
    print('fixture_function_oo3_start')
    yield 'fixture_function_oo3`s return'
    print('fixture_function_oo3_end')


@pytest.fixture(scope='function')
def fixture_function():
    print()
    print('fixture_function_start')
    yield 'fixture_function`s return'
    print()
    print('fixture_function_end')


@pytest.fixture(scope='class')
def fixture_class():
    """
    scope = class 不
    是说该 fixture 只能在 类名上使用 ,
    而是该 fixture 的运行规范是遵守 class 的 .
    """
    print()
    print('fixture_class_start')
    yield 'fixture_class`s return'
    print()
    print('fixture_class_end')


@pytest.fixture(scope='module')
def fixture_module():
    """
    scope = module 不是说该 fixture 只能在 模块 中使用 ,
    而是该 fixture 的运行规范是遵守 module 规范的 .
    """
    print()
    print('fixture_module_start')
    yield
    print()
    print('fixture_module_end')


@pytest.fixture(scope='package')
def fixture_package():
    print()
    print('fixture_package_start')
    yield
    print()
    print('fixture_package_end')


@pytest.fixture(scope='session')
def fixture_session():
    print()
    print('fixture_session_start')
    yield
    print()
    print('fixture_session_end')


@pytest.fixture(scope='class')
def fixture_class_common():
    print()
    print('fixture_class_common_start')
    yield
    print('fixture_class_common_end')
    print()
